package com.boot.main.controller;

import com.boot.main.entity.ScomAddress;
import com.boot.main.service.IAddressService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/v1/api")
@Api(tags = "地址管理")
public class AddressController {
    @Resource
    private IAddressService addressService;

    @RequestMapping(value="/address", method = RequestMethod.GET)
    @ApiOperation(value="获取地址列表")
    public Object getAddress(@RequestParam("page") Integer page, @RequestParam("limit") Integer limit, @RequestParam("name") String name){
        return addressService.getAddress(page, limit, name);
    }

    @RequestMapping(value="/address/default", method = RequestMethod.GET)
    @ApiOperation(value="获取默认地址列表")
    public Object getDefaultAddress(){
        return addressService.getDefaultAddress();
    }

    @RequestMapping(value="/address", method = RequestMethod.POST)
    @ApiOperation(value="新增地址")
    public Object saveAddress(@RequestBody ScomAddress address){
        return addressService.saveAddress(address);
    }

    @RequestMapping(value="/address/{id}", method = RequestMethod.PUT)
    @ApiOperation(value="修改地址")
    public Object updateAddress(@RequestBody ScomAddress address){
        return addressService.updateAddress(address);
    }

    @RequestMapping(value="/address/{id}", method = RequestMethod.DELETE)
    @ApiOperation(value="删除地址")
    public Object deleteAddress(@PathVariable Long id){
        return addressService.deleteAddress(id);
    }
}
